package com.wsj.message_server.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    @Bean
    public Docket createRestApi() {
        //=====添加head参数===========
        List<Parameter> pars = new ArrayList<>();
        pars.add(new ParameterBuilder().name("sign").description("签名").modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build());

        pars.add(new ParameterBuilder().name("timestamp").description("签名时间戳").modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build());

        pars.add(new ParameterBuilder().name("token").description("token").modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build());

        pars.add(new ParameterBuilder().name("devicePlatform").description("终端平台：android, ios").modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build());

        pars.add(new ParameterBuilder().name("deviceVersion").description("终端平台版本号：5.1.1").modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build());

        pars.add(new ParameterBuilder().name("deviceBrand").description("终端品牌：HUAWEI").modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build());

        pars.add(new ParameterBuilder().name("deviceType").description("终端类型：OPPO+R11+Plus").modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build());

        pars.add(new ParameterBuilder().name("deviceId").description("设备ID").modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build());


        pars.add(new ParameterBuilder().name("language").description("语言：zh-ch").modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build());

        pars.add(new ParameterBuilder().name("apiVersionCode").description("接口代码版本号: 1.0").modelRef(new ModelRef("string")).parameterType("header")
                .required(false).build());


        // =========添加head参数=============
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //.apis(RequestHandlerSelectors.basePackage("com.wsj.feed_service.controller"))
                .paths(PathSelectors.any())
                .build()
                .groupName("物料管理")
                .globalOperationParameters(pars);

    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("小宠书物料API文档")
                .description("小宠书微服务之物料API接口")
                //.termsOfServiceUrl("http://localhost:10000/material")
                .contact(new Contact("王书君", "https://www.xiaochongshump.com", "289803508@qq.com"))
                .version("1.0")
                .license("小宠书")
                .build();
    }

}
